Developer Documentation

QuickTime 4 API Documentation

QuickTime 4 Reference

| Previous | Chapter Contents | Chapter Top | Next |

Using a List Tween Component

To use a list tween component (of type kTweenTypeAtomList ), do the following:

  1. Create a QT atom container.
  2. Insert a kTweenEntry atom into the QT atom container for the tween.

  3. Insert a kTweenType atom that specifies the tween type into the kTweenEntry atom.
  4. Insert a kTweenData atom into the kTweenEntry atom.
  5. Unlike the previous example, this kTweenData atom is not a leaf atom.

  6. Insert a kListElementType atom that specifies the atom type of the list entries into the kTweenData atom
  7. The list entries must be leaf atoms.

  8. Insert leaf atoms of the type specified by the kListElementType atom into the kTweenData atom.

The duration of the tween operation is divided by the number of leaf atoms of the specified type. For time points within the first time division (from the start of the duration up to an including the time ( total time / number of atoms )), the data for the first leaf atom is returned; for the second time division, the data for the second leaf atom is returned; and so on.

Listing 7 shows how to create a list tween.

Listing 7 Creating a kTweenTypeAtomList tween container

QTAtomContainer container = nil;
long tweenDataLong[2];
QTAtomType tweenType;
QTAtom tweenAtom;

tweenDataLong[0] = EndianU32_NtoB(512);
tweenDataLong[1] = EndianU32_NtoB(0);

// create a new atom container to hold the sample
QTNewAtomContainer (&container);
// create the parent tween entry atom
tweenType = EndianU32_NtoB(kTweenTypeLong);
QTInsertChild (container, kParentAtomIsContainer, kTweenEntry, 1, 0, 0,
                nil, &tweenAtom);
// add two child atoms to the tween entry atom --
// * the type atom, kTweenType
QTInsertChild (container, tweenAtom, kTweenType, 1, 0,
                sizeof(tweenType), &tweenType, nil);
// * the data atom, kTweenData
QTInsertChild (container, tweenAtom, kTweenData, 1, 0,
                sizeof(short) * 2, tweenDataLong, nil);
OSErr       err = noErr;
QTTweener tween;
QTAtomContainer container = nil, listContainer = nil;
OSType      tweenerType;
TimeValue   offset, duration, tweenTime;
Handle      result;
QTAtom      tweenAtom;

tweenerType = EndianU32_NtoB(kTweenTypeAtomList);
offset  = 0;
duration = 3;

err = QTNewAtomContainer( &container );
if ( err ) goto bail;

err = AddTweenAtom( container, kParentAtomIsContainer, 1, tweenerType,
                    offset, duration, 0, 0, nil, &tweenAtom );
if ( err ) goto bail;

listContainer = CreateSampleAtomListTweenData( 1 );
if ( listContainer == nil ) { err = memFullErr; goto bail; }

err = AddDataAtom( container, tweenAtom, 1, 0, nil,
                    listContainer, 0, nil );
if ( err ) goto bail;

err = QTNewTween( &tween, container, tweenAtom, duration );
if ( err ) goto bail;

result = NewHandle( 0 );
if ( err = MemError() ) goto bail;
    // exercise the AtomListTweener
    for ( tweenTime = 1; tweenTime <= duration; tweenTime += 1 ) {
        long pictureID;
        
        err = QTDoTween( tween, tweenTime, result, nil, nil, nil );
        if ( err ) goto bail;
        
        // the pictureID from the atomDataList corresponding to tweenTime
        pictureID = *(long *)*result;
    }
        
    err = QTDisposeTween( tween );

bail:
    if ( container ) QTDisposeAtomContainer( container );
    if ( listContainer ) QTDisposeAtomContainer( listContainer );
    if ( result ) DisposeHandle( result );
    return err;
}

© 1999 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Next |